/*   1:    */ package com.atomikos.icatch.imp;
/*   2:    */ 
/*   3:    */ import com.atomikos.icatch.HeurCommitException;
/*   4:    */ import com.atomikos.icatch.HeurHazardException;
/*   5:    */ import com.atomikos.icatch.HeurMixedException;
/*   6:    */ import java.util.Enumeration;
/*   7:    */ import java.util.Hashtable;
/*   8:    */ import java.util.Stack;
/*   9:    */ import java.util.Vector;
/*  10:    */ 
/*  11:    */ class PrepareResult
/*  12:    */   extends Result
/*  13:    */ {
/*  14: 45 */   protected Hashtable readonlytable_ = new Hashtable();
/*  15: 47 */   protected Hashtable indoubts_ = new Hashtable();
/*  16: 51 */   protected Hashtable heuristics_ = new Hashtable();
/*  17: 53 */   protected boolean analyzed_ = false;
/*  18: 55 */   protected Vector msgvector_ = new Vector();
/*  19:    */   
/*  20:    */   public PrepareResult(int count)
/*  21:    */   {
/*  22: 66 */     super(count);
/*  23:    */   }
/*  24:    */   
/*  25:    */   protected synchronized void analyze()
/*  26:    */     throws IllegalStateException, InterruptedException
/*  27:    */   {
/*  28: 72 */     if (this.analyzed_) {
/*  29: 73 */       return;
/*  30:    */     }
/*  31: 75 */     boolean allReadOnly = true;
/*  32: 76 */     boolean allYes = true;
/*  33: 77 */     boolean heurmixed = false;
/*  34: 78 */     boolean heurhazards = false;
/*  35: 79 */     boolean heurcommits = false;
/*  36: 80 */     Stack replies = getReplies();
/*  37: 81 */     Enumeration enumm = replies.elements();
/*  38: 83 */     while (enumm.hasMoreElements())
/*  39:    */     {
/*  40: 84 */       boolean yes = false;
/*  41: 85 */       boolean readonly = false;
/*  42:    */       
/*  43: 87 */       Reply reply = (Reply)enumm.nextElement();
/*  44: 89 */       if (reply.hasFailed())
/*  45:    */       {
/*  46: 90 */         yes = false;
/*  47: 91 */         readonly = false;
/*  48:    */         
/*  49: 93 */         Exception err = reply.getException();
/*  50: 94 */         if ((err instanceof HeurMixedException))
/*  51:    */         {
/*  52: 95 */           heurmixed = true;
/*  53: 96 */           HeurMixedException hm = (HeurMixedException)err;
/*  54: 97 */           addMessages(hm.getHeuristicMessages());
/*  55:    */         }
/*  56: 98 */         else if ((err instanceof HeurCommitException))
/*  57:    */         {
/*  58: 99 */           heurcommits = true;
/*  59:100 */           HeurCommitException hc = (HeurCommitException)err;
/*  60:101 */           addMessages(hc.getHeuristicMessages());
/*  61:102 */           heurmixed = (heurmixed) || (heurhazards);
/*  62:    */         }
/*  63:103 */         else if ((err instanceof HeurHazardException))
/*  64:    */         {
/*  65:104 */           heurhazards = true;
/*  66:105 */           heurmixed = (heurmixed) || (heurcommits);
/*  67:106 */           HeurHazardException hr = (HeurHazardException)err;
/*  68:107 */           this.indoubts_.put(reply.getParticipant(), new Boolean(true));
/*  69:    */           
/*  70:    */ 
/*  71:    */ 
/*  72:111 */           addMessages(hr.getHeuristicMessages());
/*  73:    */         }
/*  74:    */       }
/*  75:    */       else
/*  76:    */       {
/*  77:117 */         readonly = reply.getResponse() == null;
/*  78:118 */         Boolean answer = new Boolean(false);
/*  79:119 */         if (!readonly) {
/*  80:120 */           answer = (Boolean)reply.getResponse();
/*  81:    */         }
/*  82:122 */         yes = (readonly) || (answer.booleanValue());
/*  83:125 */         if (readonly) {
/*  84:126 */           this.readonlytable_.put(reply.getParticipant(), new Boolean(true));
/*  85:    */         } else {
/*  86:129 */           this.indoubts_.put(reply.getParticipant(), new Boolean(true));
/*  87:    */         }
/*  88:    */       }
/*  89:133 */       allYes = (allYes) && (yes);
/*  90:134 */       allReadOnly = (allReadOnly) && (readonly);
/*  91:    */     }
/*  92:138 */     if (heurmixed) {
/*  93:139 */       this.result_ = 2;
/*  94:140 */     } else if (heurcommits) {
/*  95:141 */       this.result_ = 4;
/*  96:142 */     } else if (heurhazards) {
/*  97:143 */       this.result_ = 1;
/*  98:144 */     } else if (allReadOnly) {
/*  99:145 */       this.result_ = 5;
/* 100:146 */     } else if (allYes) {
/* 101:147 */       this.result_ = 0;
/* 102:    */     }
/* 103:149 */     this.analyzed_ = true;
/* 104:    */   }
/* 105:    */   
/* 106:    */   public boolean allYes()
/* 107:    */     throws InterruptedException
/* 108:    */   {
/* 109:163 */     analyze();
/* 110:164 */     return (this.result_ == 0) || (this.result_ == 5);
/* 111:    */   }
/* 112:    */   
/* 113:    */   public boolean allReadOnly()
/* 114:    */     throws InterruptedException
/* 115:    */   {
/* 116:178 */     analyze();
/* 117:179 */     return this.result_ == 5;
/* 118:    */   }
/* 119:    */   
/* 120:    */   public Hashtable getReadOnlyTable()
/* 121:    */     throws InterruptedException
/* 122:    */   {
/* 123:192 */     analyze();
/* 124:193 */     return this.readonlytable_;
/* 125:    */   }
/* 126:    */   
/* 127:    */   public Hashtable getIndoubtTable()
/* 128:    */     throws InterruptedException
/* 129:    */   {
/* 130:207 */     analyze();
/* 131:208 */     return this.indoubts_;
/* 132:    */   }
/* 133:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\transactions\3.7.0\transactions-3.7.0.jar
 * Qualified Name:     com.atomikos.icatch.imp.PrepareResult
 * JD-Core Version:    0.7.0.1
 */